{%extends file='layout/layout.html' %}
{%block name="content"%}
<div class="hastable">

    <div style="margin-bottom: 10px">

        <label class="btn btn-success btn-sm" onclick=goback("/admin/downshare")><i class="fa fa-download"></i>批量导出</label>
    </div>

    <div style="margin-bottom: 10px">
        <label style="margin-right: 10px">手机/姓名:</label><input style="margin-right: 10px" type="text" name="search" value="{%$search|default:''%}">
        <label style="margin-right: 10px">状态:</label>
        <select  class="field select" id="selectstate" >
            <option {%if $state eq -1%}selected{%/if%} value="-1">
                全部
            </option>
            <option  {%if $state eq 0%}selected{%/if%} value="0">
                审核中
            </option>
            <option {%if $state eq 1%}selected{%/if%}  value="1">
                上传失败
            </option>
            <option {%if  $state eq 2%}selected{%/if%} value="2">
                审核失败
            </option>
            <option {%if $state eq 3%}selected{%/if%} value="3">
                审核成功
            </option>
        </select>
        <label class="btn btn-success btn-sm" onclick="doserch()"><i class="fa fa-search"></i>检索</label>
        <label class="btn btn-success btn-sm" onclick="reset()"><i class="fa fa-remove"></i>清空</label>
    </div>

    <table>

        <thead>
        <tr>
            <th>序号</th>
            <th>姓名</th>
            <th>手机号</th>
            <th>上传图片</th>
            <th>上传类型</th>
            <th>积分</th>
            <th>原因</th>
            <th>状态</th>
            <th>上传日期</th>
            <th style="width:132px">操作</th>
        </tr>
        </thead>
        <tbody>
        {%if $data|@count neq 0 %}
        {%foreach $data as $key=>$value%}
        <tr class="{%if $key%2 neq 0 %}even{%else%}odd{%/if%}">
            <td class="center">{%$key+1%}</td>
            <td>{%$value.username|default:''%}</td>
            <td>{%$value.mobile|default:''%}</td>
            <td>{%if $value.media neq '' %}<img src="/upload/thumb/{%$value.media%}" width="150" />{%/if%}</td>
            <td>{%$value.mediatype|default:''%}</td>
            <td>+{%$value.integral|default:0%}</td>
            <td>{%$value.rank|default:''%}</td>
            <td>{%if $value.state eq 1 %}上传失败{%elseif $value.state eq 2 %}审核失败{%elseif $value.state eq 3 %}审核成功{%else%}审核中{%/if%}</td>
            <td>{%$value.createtime|date_format:'%Y-%m-%d'|default:''%}</td>
            <td>
               {%if $value.state eq 0 or $value.state eq 1%}
                <label class="btn btn-sm btn-success" attrid="{%$value.id%}" attruid="{%$value.uid%}"  onclick="editrow(this)"><i class="fa fa-edit"></i>审核</label>
                {%else%}
                <label><i class="fa fa-edit"></i>已审核</label>
                {%/if%}
            </td>
        </tr>
        {%/foreach%}
        {%else%}
        <tr class="even">
            <td colspan="10" style="text-align: center">无内容</td>
        </tr>
        {%/if%}

        </tbody>

    </table>

    <ul style="width:50%;margin: 0 auto;text-align: center" id="pagination"></ul>

</div>
<div id="editrow" class="dno">
    <div class="forms" >
        <ul>
            <li>
                <div>
                    <select tabindex="3" class="field select" id="state">
                        <option value="2">
                            审核失败
                        </option>
                        <option value="3">
                            审核成功
                        </option>
                    </select>
                </div>
            </li>
            <li>
                <label class="desc">
                   积分
                </label>
                <div>
                    <input type="text" class="field text" id="integral">
                </div>
            </li>
            <li>
                <label class="desc">
                    原因
                </label>
                <div>
                    <textarea tabindex="2" cols="50" rows="5"  style="resize:none"  class="field textarea small" id="rank"></textarea>
                </div>
            </li>

        </ul>
    </div>
</div>
<div class="clearfix"></div>

{%/block%}
{%block name="js" append%}
<script type="text/javascript">

    $(function () {
        init()
    })
    function init() {
        $(".datepicker").datepicker({
            dateFormat: "yy-mm-dd",
            showOtherMonths: true,
            selectOtherMonths: true,
            showButtonPanel: true,
            showOn: "both",
            buttonImageOnly: true,
            buttonText: "",
            changeMonth: true,
            changeYear: true
        });
        {%if $data|@count neq 0 %}

        $("#pagination").twbsPagination("destroy");
        $('#pagination').twbsPagination({
            startPage: parseInt("{%$page|default:1%}"),
            initiateStartPageClick: false,
            totalPages: parseInt("{%$total%}"),
            visiblePages: 10,
            first: '首页',
            last: '尾页',
            prev: '«',
            next: '»',

            nextClass: 'next',
            activeClass: 'active',
            disabledClass: 'previous-off',
            anchorClass: '',
            onPageClick: function (event, pager) {
                var data = {page: pager};
                window.location.href = '/admin/share/' + $.base64.btoa(JSON.stringify(data));

            }

        });
        {%/if%}
    }

   function editrow(obj) {
        var id =obj.getAttribute('attrid');
       var uid =obj.getAttribute('attruid');
       $("#editrow").dialog({
           title: "审核",
           closeOnEscape: false,
           //隐藏默认的关闭按钮
           open: function (event, ui) {
               $(".ui-dialog-titlebar-close", $(this).parent()).hide();
           },
           buttons:{
               "保存":function(){
                   var state=$("#state").val();
                    var integral=$("#integral").val();
                    if(state==3){
                        var rank=$("#rank").val();
                        if(!isDigits(integral)){
                            showmsg("积分格式错误", 2);
                            dorefulsh();
                        }
                    }

                   $.post('/api/saveshare.json',{id:id,uid:uid,state:state,integral:integral,rank:rank,tk_name:"{%$tk_name%}",tk_value:"{%$tk_value%}"},function (data, textStatus, jqXHR) {
                       if(jqXHR.status==200){
                           showmsg(jqXHR.responseText, 1);
                           dorefulsh();
                       }else{
                           showmsg(jqXHR.responseText, 2);
                       }
                   })
               },
               "取消":function(){$(this).dialog('close');}
           }
       })
   }
    function doserch() {
        var search = $("input[name='search']").val();
        var  selectstate = $("#selectstate").val();
        var data = {
            search: escape($.trim(search)),
            state: selectstate,
            page: parseInt("{%$page|default:1%}")
        };

        window.location.href = '/admin/share/' + $.base64.btoa(JSON.stringify(data));

    }

    function reset() {
        $("input[name='search']").val('');
        window.location.href = '/admin/share';
    }

</script>
{%/block%}
